home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / mathstud.zip / TRACE.M < prev    next >
Text File  |  1993-03-23  |  348b  |  20 lines

  1. function y = trace(X)
  2. %y=trace(X)
  3. %trace Compute the trace of matrix X
  4.  
  5. %       S.Halevy 7/31/92
  6. %       Copyright (c) 1992 by the MathWizards
  7.  
  8. if nargin < 1
  9.    error('not enough arguments')
  10. end
  11. if nargin > 1
  12.    error('too many arguments')
  13. end
  14. if isvector(X)
  15.    error('trace - argument must be a matrix')
  16. end
  17.  
  18. y = sum(diag(X));
  19.  
  20.